package com.lanou.hotel.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lanou.hotel.entity.Guests;
import com.lanou.hotel.entity.response.GuestsItem;
import com.lanou.hotel.mapper.GuestsMapper;
import com.lanou.hotel.service.IGuestsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lanou.hotel.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author msy
 * @since 2023-10-29
 */
@Service
public class GuestsServiceImpl extends ServiceImpl<GuestsMapper, Guests> implements IGuestsService {

    @Autowired
    private GuestsMapper guestsMapper;

    /**
     * 分页+条件查询租客列表
     * @param guests
     * @param startTime
     * @param endTime
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public ResultVO<Map<String, Object>> getGuests(Guests guests, String startTime, String endTime, Integer pageNum, Integer pageSize) {

        Page<Guests> guestsPage = new Page<>(pageNum,pageSize);

        List<GuestsItem> guestsList = guestsMapper.getGuests(guestsPage,guests,startTime,endTime);
        long total = guestsPage.getTotal();//获取总数

        if (guestsList != null) {
            Map<String, Object> map = new HashMap<>();
            map.put("guestsList",guestsList);
            map.put("total",total);

            return ResultVO.success("请求成功",map);
        }
        return ResultVO.failed("系统繁忙,请稍后重试...");
    }
}
